<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>会员登录</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">     
    <meta content="yes" name="apple-mobile-web-app-capable">     
    <meta content="black" name="apple-mobile-web-app-status-bar-style">     
    <meta content="telephone=no" name="format-detection">
    <link rel="shortcut icon" href="/favicon.ico">
    <link rel="stylesheet" type="text/css" href="/H5/css/sm.min.css" />
    <link rel="stylesheet" type="text/css" href="/H5/css/login.shell.css?v=4" />
</head>
<body>
    <div class="page-group ms-controller" :controller="login">
        <div class="page page-current">
            <div class="content">
                <div class="login_shell">
                    <div class="login_logo"><a href="javascript:;"><img style="display: none" src="/logo" class="maxWidth"/></a></div>
                    <div class="login_inpt">
                        <input type="text" autocomplete="off" class="number_tel" name="username" :duplex="@userName" placeholder="请输入手机号或会员账号"/>
                        <input type="text" name="username" style="position:absolute; top:0; left: 0; visibility: hidden"/>
                        <input type="password" name="userPassword" style="position:absolute; top:0; left: 0; visibility: hidden"/>
                        <input type="password" autocomplete="off" class="number_password" name="userPassword" :duplex="@password" placeholder="请输入登录密码"/>
                    </div>
                    <div class="login_button">
                        <!-- <div class="login_mm"><a href="retrieve.html">忘记密码?</a></div> -->
                        <div id="login_zc" class="login_zc">还没账号？<a href="/H5/register" style="color:#0075c5;">我要注册</a>
                            <!--<a href="/H5/reset" style="color:#0075c5; padding-left: 10px">忘记密码</a>-->
                        </div>
                        <button :on-click="@lg" class="lg">登&nbsp;&nbsp;&nbsp;录</button>
                       <!--<button style="background-color: #2f7832;margin-top:1.5rem;" :on-click="@wxLogin" class="lg">微信登录</button>-->
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type='text/javascript' src='/H5/js/zepto.min.js' charset='utf-8'></script>
    <script type='text/javascript' src='/H5/js/sm.min.js' charset='utf-8'></script>
    <script type='text/javascript' src='/H5/js/avalon.js' charset='utf-8'></script>
    <script type='text/javascript' src='/H5/js/simpleStorage.js' charset='utf-8'></script>
    <script type='text/javascript' src='/H5/js/mall.js?v=10' charset='utf-8'></script>
    <script>
        var login = avalon.define({
            $id: "login",
            userName: "",
            password: "",
            inviteCode: simpleStorage.get( "inviteCode" )||"",
            lock: false,
            lg: function(){
                if( !this.userName ){
                    $.toast("请输入用户名",2000,"warning")
                    return
                }
                if(!this.password){
                    $.toast("请输入密码",2000,"warning")
                    return
                }
                if( login.lock ){
                    return
                }
                login.lock = true;
                $( ".lg" ).html('<div class="loadingCss"></div>')
                Mall.request( "/api/Login", { username: login.userName, password: login.password } )
                    .always( function( data ){
                        if( data.error_code == 0 ){
                            simpleStorage.set("token", data.data.api_token);
                            simpleStorage.set("expire_time", data.data.expire_time*1000);
                            login.squan();
                            Mall.request( "/api/UserInfo" )
                                .always( function( data ){
                                    if( data.error_code == 0 ){
                                        simpleStorage.set( "myInviteCode", data.data.invite_code);
                                        if( simpleStorage.get("toUrl") ){
                                            window.location.href = simpleStorage.get("toUrl");
                                        }
                                        else{
                                            window.location.href = "/index/oauth";
                                        }
                                    }
                                } )
                        }
                        $( ".lg" ).html("登&nbsp;&nbsp;&nbsp;录")
                        login.lock = false;
                    } )
            },
            squan: function(){
                var is_weixin = (function(){return navigator.userAgent.toLowerCase().indexOf('micromessenger') !== -1})();
                var url = "";
                if( simpleStorage.get("toUrl") ){
                    url = simpleStorage.get("toUrl");
                }
                else{
                    url = window.location.href
                }
                if(is_weixin){
                    if( Mall.parseUrl( window.location.href ).c ){
                        Mall.request("/api/Logout")
                            .always(function(data){
                                if( data.error_code == 0 ){
                                    simpleStorage.set('token', undefined);
                                    simpleStorage.set('isOauth', undefined);
                                    window.location.href='/H5/login';
                                }
                          })
                    }
                    else{
                        Mall.request("/api/OauthCheck",{jump_url: url})
                            .always( function( data ){
                                if( data.error_code == 0 ){
                                    if( data.data.is_oauth ){
                                        if( data.data.api_token ){
                                            simpleStorage.set("token", data.data.api_token);
                                            simpleStorage.set("expire_time", data.data.expire_time*1000);
                                            window.location.href='/H5?c=1';
                                        }
                                    }
                                    else{
                                        window.location.href = data.data.oauth_url;
                                    }
                                    simpleStorage.set("isOauth", data.data.is_oauth);
                                }
                            } )
                    }
                }
            },
            wxLogin: function(){
                window.location.href="/wap/index/wxReg?inviteCode="+login.inviteCode;
            },
            checkLogin: function(){
                if( simpleStorage.get("token") && simpleStorage.get("isOauth") ){
                    if( simpleStorage.get("toUrl") ){
                        window.location.href = simpleStorage.get("toUrl");
                    }
                }

            }
        })
        // login.checkLogin();
        var ua = window.navigator.userAgent.toLowerCase();
        if(ua.match(/MicroMessenger/i) == 'micromessenger'){
            window.location.href="/index/wap/index/wxReg?inviteCode=".simpleStorage.get("inviteCode");
        }
        if(!simpleStorage.get("wap_reg_api_open")){
            document.getElementById('login_zc').style.display="none";
        }
        avalon.scan( document.body )
    </script>
</body>
</html>
